package com.yanqu.road.server.cmd.activity.signindraw;

import com.yanqu.road.entity.activity.signindraw.SignInDrawUserData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SignInDrawProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.signindraw.SignInDrawActivityPb;
import com.yanqu.road.server.gameplayer.module.activity.signindraw.SignInDrawModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.signindraw.SignInDrawActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_SIGN_IN_DRAW_GET_USER_DATA, desc = "获取玩家数据")
public class SignInDrawGetUserDataCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        // 没有活动
        if (!ActivityMgr.activityInShowTime(SignInDrawActivityMgr.getActivityInfo()) || SignInDrawActivityMgr.getConfig() == null) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        SignInDrawUserData userData = player.getModule(SignInDrawModule.class).getUserData();
        if(userData == null){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }

        SignInDrawProto.SignInDrawGetUserDataRespMsg.Builder builder = SignInDrawProto.SignInDrawGetUserDataRespMsg.newBuilder().setRet(ret);
        builder.setUserData(SignInDrawActivityPb.buildUserData(userData));
        player.sendPacket(Protocol.U_SIGN_IN_DRAW_GET_USER_DATA, builder);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_SIGN_IN_DRAW_GET_USER_DATA, SignInDrawProto.SignInDrawGetUserDataRespMsg.newBuilder().setRet(ret));
        }
    }
}
